package com.shigen.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shigen.demo.entity.FirstMenu;
import com.shigen.demo.entity.SecondMenu;
import com.shigen.demo.mapper.FirstMenuMapper;
import com.shigen.demo.mapper.SecondMenuMapper;
import com.shigen.demo.service.IMenuService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class MenuServiceImpl extends ServiceImpl<FirstMenuMapper, FirstMenu> implements IMenuService {

  @Resource
  private SecondMenuMapper secondMenuMapper;

  @Override
  public List<FirstMenu> getAllMenus() {
    List<FirstMenu> firstMenus;
    firstMenus = getBaseMapper().selectList(null);
    for (FirstMenu firstMenu : firstMenus) {
      QueryWrapper<SecondMenu> queryWrapper = new QueryWrapper<SecondMenu>();
      queryWrapper.eq("p_id", firstMenu.getId());
      List<SecondMenu> secondMenus = secondMenuMapper.selectList(queryWrapper);
      firstMenu.setSecondMenus(secondMenus);
    }
    return firstMenus;
  }
}
